﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="Delivery.cs" company="Oliver Kurowski">
//    (c) Oliver Kurowski. All rights reserved.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------
namespace RegioKistl.Models
{
    using System;
    using System.ComponentModel.DataAnnotations;

    using RegioKistl.Resources;

    public class Delivery
    {
        private bool wasHelping;

        private int takenBoxesCount;

        private int returnedBoxesCount;

        /// <summary>
        /// The price of deliveries per month. It is defined that
        /// a weeks delivery costs PricePerMonth/h.
        /// </summary>
        public const decimal PricePerMonth = 60.0m;

        /// <summary>
        /// The price of a box. Each customer owns 2 boxes. So one box is at the customer,
        /// one box in the shop. When a customer didn't return the box, he can take another,
        /// but is billed for it.
        /// </summary>
        public const decimal PriceOfBox = 10.0m;

        public int Id { get; set; }

        public int CustomerId { get; set; }

        [Display(Name = "DeliveryDate", ResourceType = typeof(DeliveryTexts))]
        public DateTime DeliveryDate { get; set; }

        [Display(Name = "WasHelping", ResourceType = typeof(DeliveryTexts))]
        public bool WasHelping
        {
            get
            {
                return this.wasHelping;
            }

            set
            {
                this.wasHelping = value;
                this.CalculatePrice();
            }
        }

        [Display(Name = "TakenBoxesCount", ResourceType = typeof(DeliveryTexts))]
        public int TakenBoxesCount
        {
            get
            {
                return this.takenBoxesCount;
            }

            set
            {
                this.takenBoxesCount = value;
                this.CalculatePrice();
            }
        }

        [Display(Name = "ReturnedBoxesCount", ResourceType = typeof(DeliveryTexts))]
        public int ReturnedBoxesCount
        {
            get
            {
                return this.returnedBoxesCount;
            }

            set
            {
                this.returnedBoxesCount = value;
                this.CalculatePrice();
            }
        }

        [Display(Name = "PriceForTransaction", ResourceType = typeof(DeliveryTexts))]
        public decimal PriceForTransaction { get; private set; }

        /// <summary>
        /// Calculates the price.
        /// </summary>
        public void CalculatePrice()
        {
            decimal price = 0;

            if (!this.WasHelping)
            {
                price += PricePerMonth / 4;
            }

            // calculate price for boxes
            price += (this.TakenBoxesCount - this.ReturnedBoxesCount) * PriceOfBox;

            this.PriceForTransaction = price;
        }
    }
}